//
//  VerifyViewController.m
//  JinMaJiaDemo
//
//  Created by GripMeMory on 16/1/12.
//  Copyright © 2016年 GripMeMory. All rights reserved.
//

#import "VerifyViewController.h"
#import "JMJLoginTextField.h"
#import "UserPasswordViewController.h"

#define kNoticeViewHeight 75 / 2
#define kTextFieldTopMargin 45 / 2
#define kTextFieldLeftMargin 30 / 2
#define kTextFieldSeparateMargin 20 / 2
#define kTextFieldMidMargin 30 / 2
#define kTextFieldHeight 60 / 2
#define kVerifyWidth 100
#define kVerifyButtonWidth 100

@interface VerifyViewController ()

@end

@implementation VerifyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customNav];
    [self customMainView];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.tabBarController.tabBar.hidden = NO;
}

#pragma mark - Custom User Interface

- (void)customNav{
    self.title = @"注册2/3";
    UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(bbiClick:)];
    self.navigationItem.leftBarButtonItem = bbi;
}

- (void)customMainView{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, UISCREENWIDTH, kNoticeViewHeight)];
    label.backgroundColor = RGB_COLOR(@"#f19d57");
    label.text = [NSString stringWithFormat:@"验证码短信发送至%@", @"18713516789"];
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(kTextFieldLeftMargin, label.bottom + kTextFieldTopMargin, UISCREENWIDTH - 2 * kTextFieldLeftMargin, 1)];
    view.backgroundColor = RGB_COLOR(@"#c9c9c9");
    [self.view addSubview:view];
    
    UILabel *verifyLabel = [[UILabel alloc] initWithFrame:CGRectMake(view.left, view.bottom + kTextFieldSeparateMargin, kVerifyWidth, kTextFieldHeight)];
    verifyLabel.text = @"验证码";
    verifyLabel.textAlignment = NSTextAlignmentCenter;
    verifyLabel.adjustsFontSizeToFitWidth = YES;
    [self.view addSubview:verifyLabel];
    
    UIButton *verifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    verifyButton.frame = CGRectMake(view.right - kVerifyButtonWidth, view.bottom + kTextFieldSeparateMargin, kVerifyButtonWidth, kTextFieldHeight);
    [verifyButton setTitle:@"59s后重发" forState:UIControlStateNormal];
    verifyButton.layer.cornerRadius = 5;
    verifyButton.tintColor = RGB_COLOR(@"#c9c9c9");
    [verifyButton setBackgroundColor:RGB_COLOR(@"#c9c9c9")];
    [verifyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:verifyButton];
    
    JMJNormalTextField *textField = [[JMJNormalTextField alloc] initWithFrame:CGRectMake(verifyLabel.right + kTextFieldMidMargin, view.bottom + kTextFieldSeparateMargin, view.width - kVerifyWidth - kVerifyButtonWidth - 2 * kTextFieldMidMargin, kTextFieldHeight)];
    textField.layer.borderWidth = 2;
    textField.layer.cornerRadius = 3;
    textField.layer.borderColor = [RGB_COLOR(@"#c9c9c9") CGColor];
    [self.view addSubview:textField];
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(view.left, verifyLabel.bottom + kTextFieldSeparateMargin, view.width, 1)];
    view2.backgroundColor = RGB_COLOR(@"#c9c9c9");
    [self.view addSubview:view2];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(view.left, view2.bottom + kTextFieldTopMargin, view.width,  kTextFieldHeight + 2 * kTextFieldSeparateMargin);
    [button setTitle:@"下一步,设置用户名密码" forState:UIControlStateNormal];
    button.backgroundColor = RGB_COLOR(@"#d91f00");
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.layer.cornerRadius = 5;
    [button addTarget:self action:@selector(registerButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

#pragma mark - Action

- (void)bbiClick:(UIBarButtonItem *)bbi{
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)registerButtonClick{
    UserPasswordViewController *upvc = [[UserPasswordViewController alloc] init];
    [self.navigationController pushViewController:upvc animated:NO];
}

@end
